package com.fansl.koala.quickdev.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * @author fansl
 * @Description: 性别枚举类
 * @date 2020/3/17 15:51
 */
@Getter
@AllArgsConstructor
public enum  GenderEnum {
    /**
     * 男
     */
    MALE("1","男"),
    /**
     * 女
     */
    FEMALE("2","女"),
    /**
     * 未知
     */
    UNKNOWN("3","未知"),
    ;
    private final String code;
    private final String message;

    /**
     * 根据code获取枚举值，未找到默认为unknown
     * @param code 代码
     * @return 枚举成员
     */
    public static GenderEnum findByCode(String code){
        return Arrays.stream(GenderEnum.values())
                .filter(enumMember -> enumMember.getCode().equals(code))
                .findFirst()
                .orElse(GenderEnum.UNKNOWN);
    }
}
